/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ru.ipccenter.ejb;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;


/**
 *
 * @author Nick
 */
@Entity
@Table(name = "USERS")
@NamedQueries({
    //@NamedQuery(name = "Users.findAll", query = "SELECT u FROM USERS u"),
    @NamedQuery(name = "Users.findPassByUsername", query = "SELECT u.pass FROM User u WHERE u.userName = :username"),
    @NamedQuery(name="Users.findAllName", query="select u.userName from User u"),
    @NamedQuery(name="Users.findAllMail", query="select u.userMail from User u"),
    @NamedQuery(name = "Users.findPassByMail", query = "SELECT u.userName, u.pass FROM User u WHERE u.userMail= :usermail")})
public class User implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer userId;

    @Basic(optional = false)
    @Column(name = "USERNAME", unique = true)
    private String userName;

    @Basic(optional = false)
    @Column(name = "PASS")
    private String pass;

    @Basic(optional = false)
    @Column(name = "USERMAIL", unique = true)
    private String userMail;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "REGDATE")
    private Date regDate;

    public User() {
    }
//
//    public User(String username) {
//        this.username = username;
//    }

    public User(String userName, String pass, String mail) {
        this.userName = userName;
        this.pass = pass;
        this.userMail = mail;
        this.regDate = new Timestamp((new Date()).getTime());//Calendar.getInstance().getTime();
    }

    public String getUsername() {
        return userName;
    }

    public void setUsername(String userName) {
        this.userName = userName;
    }

    public String getPass() {
        return pass;
    }

    public void setPass(String pass) {
        this.pass = pass;
    }

    public String getMail() {
        return userMail;
    }

    public void setMail(String mail) {
        this.userMail = mail;
    }

    public Date getRegDate() {
        return regDate;
    }

    public void setRegDate(Date regDate) {
        this.regDate = regDate;
    }

    public Integer getUserId() {
        return userId;
    }
    public void setUserId(Integer userId) {
        this.userId = userId;
    }
//    @Override
//    public int hashCode() {
//        int hash = 0;
//        hash += (userName != null ? userName.hashCode() : 0);
//        return hash;
//    }

//    @Override
//    public boolean equals(Object object) {
//        // TODO: Warning - this method won't work in the case the id fields are not set
//        if (!(object instanceof User)) {
//            return false;
//        }
//        User other = (User) object;
//        if ((this.userName == null && other.userName != null) || (this.userName != null && !this.userName.equals(other.userName))) {
//            return false;
//        }
//        return true;
//    }

//    @Override
//    public String toString() {
//        return "ru.ipccenter.ejb.Login[userName=" + userName + "]";
//    }



}
